package com.bdjk.bdmw.InfoGath.business.nurse.vo;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.druid.util.StringUtils;
import com.bdjk.bdmw.InfoGath.business.LBS.service.LBSLocationService;
import com.bdjk.bdmw.InfoGath.business.LBS.service.impl.LBSLocationServiceImpl;
import com.bdjk.bdmw.InfoGath.business.iparent.model.IparentPositionModel;
import com.bdjk.bdmw.InfoGath.business.nurse.model.NursePositionModel;
import com.bdjk.bdmw.InfoGath.common.constants.InfoGathConstants;
import com.bdjk.bdmw.InfoGath.common.model.BaseModel;
import com.bdjk.bdmw.InfoGath.common.model.LBSModel;
import com.bdjk.bdmw.InfoGath.common.vo.BaseVO;

public class NursePositionVO extends BaseVO {
	private String Id;
	private String proVersion;
	private String mesId;
	private String encryptType;
	private String validatCode;
	private String sendTime;
	private String terType;
	private String terIdent;
	private String timeZone;
	private String mesType;
	private String electricity;
	private String baseInfo;
	private String collectMills;
	private String longitude;
	private String latitude;
	private String altitude;
	private String speed;
	private String direction;
	private String dataType;
	public String getProVersion() {
		return proVersion;
	}
	public void setProVersion(String proVersion) {
		this.proVersion = proVersion;
	}
	public String getMesId() {
		return mesId;
	}
	public void setMesId(String mesId) {
		this.mesId = mesId;
	}
	public String getEncryptType() {
		return encryptType;
	}
	public void setEncryptType(String encryptType) {
		this.encryptType = encryptType;
	}
	public String getValidatCode() {
		return validatCode;
	}
	public void setValidatCode(String validatCode) {
		this.validatCode = validatCode;
	}
	public String getSendTime() {
		return sendTime;
	}
	public void setSendTime(String sendTime) {
		this.sendTime = sendTime;
	}
	public String getTerType() {
		return terType;
	}
	public void setTerType(String terType) {
		this.terType = terType;
	}
	public String getTerIdent() {
		return terIdent;
	}
	public void setTerIdent(String terIdent) {
		this.terIdent = terIdent;
	}
	public String getTimeZone() {
		return timeZone;
	}
	public void setTimeZone(String timeZone) {
		this.timeZone = timeZone;
	}
	public String getMesType() {
		return mesType;
	}
	public void setMesType(String mesType) {
		this.mesType = mesType;
	}
	public String getElectricity() {
		return electricity;
	}
	public void setElectricity(String electricity) {
		this.electricity = electricity;
	}
	public String getBaseInfo() {
		return baseInfo;
	}
	public void setBaseInfo(String baseInfo) {
		this.baseInfo = baseInfo;
	}
	public String getCollectMills() {
		return collectMills;
	}
	public void setCollectMills(String collectMills) {
		this.collectMills = collectMills;
	}
	public String getLongitude() {
		return longitude;
	}
	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}
	public String getLatitude() {
		return latitude;
	}
	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}
	public String getId() {
		return Id;
	}
	public void setId(String id) {
		Id = id;
	}
	public String getAltitude() {
		return altitude;
	}
	public void setAltitude(String altitude) {
		this.altitude = altitude;
	}
	public String getSpeed() {
		return speed;
	}
	public void setSpeed(String speed) {
		this.speed = speed;
	}
	public String getDirection() {
		return direction;
	}
	public void setDirection(String direction) {
		this.direction = direction;
	}
	public String getDataType() {
		return dataType;
	}
	public void setDataType(String dataType) {
		this.dataType = dataType;
	}
	@Override
	public NursePositionModel vo2Model() throws ParseException {
		// TODO Auto-generated method stub
		NursePositionModel model = new NursePositionModel();
		model.setProVersion(this.proVersion);
		model.setEncryptType(this.encryptType);
		model.setValidatCode(this.validatCode);
		if(!StringUtils.isEmpty(this.sendTime)){
			model.setSendTime(InfoGathConstants.SDF.parse(this.sendTime));//sendtime:"2002-10-8 15:30:22"
		}
		model.setTerType(this.terType);
		model.setTerIdent(this.terIdent);
		model.setTimeZone(this.timeZone);
		model.setMesType(this.mesType);
        model.setBaseInfo(this.baseInfo);
		model.setLbsModels(getLBSModel(this.baseInfo));
		if(!StringUtils.isEmpty(this.longitude)){
			model.setLongitude(Double.valueOf(this.longitude));
		}
		if(!StringUtils.isEmpty(this.latitude)){
			model.setLatitude(Double.valueOf(this.latitude));
		}
		if(!StringUtils.isEmpty(this.altitude)){
			model.setAltitude(Double.valueOf(this.altitude));
		}
		if(!StringUtils.isEmpty(this.speed)){
			model.setSpeed(Double.valueOf(this.speed));
		}
		if(!StringUtils.isEmpty(this.direction)){
			model.setDirection(Double.valueOf(this.direction));
		}
		
		if(!StringUtils.isEmpty(this.collectMills)){
			model.setCollectMills(InfoGathConstants.SDF.parse(this.collectMills));//sendtime:"2002-10-8 15:30:22"
		}
		//model.setCollectMills(this.collectMills);
		
		
		
		
		return  model;
	}
	public List<LBSModel> getLBSModel(String baseInfo){
    	List<LBSModel> lbsModel=new ArrayList<LBSModel>();
    	if(!StringUtils.isEmpty(this.longitude)||!StringUtils.isEmpty(this.latitude)){
    		return lbsModel;
    	}
    	String[] params=baseInfo.split("\\$");
    	
    	
    	if(params[0].equals("count")){
    		String[] temps=params[2].split("\\|");
    		LBSModel model=new LBSModel();
    		model.setLacId(Long.valueOf(temps[1]));
    		model.setCellId(Long.valueOf(temps[2]));
    		model.setIntense(100);
    		lbsModel.add(model);
    	}else if(params[0].equals("mcount")){
    		if(params[1].equals("0")) return lbsModel;
    		String[] temps=params[4].split("#");
    		for(int i=1;i<temps.length;i++){
    			String[] lbs=temps[i].split("\\|");
    			LBSModel model=new LBSModel();
    			model.setLacId(Long.valueOf(lbs[0],16));
    			model.setCellId(Long.valueOf(lbs[1],16));
    			model.setIntense(Long.valueOf(lbs[3]));
    			lbsModel.add(model);
    		}
    	}
    	LBSLocationService lbsLocationService=new LBSLocationServiceImpl();
    	double[] pos=lbsLocationService.getTermLocation(lbsModel);
    	//mode和VOl设经纬度
    	this.setLongitude(String.valueOf(pos[0]));
    	this.setLatitude(String.valueOf(pos[1]));
    	return lbsModel;
    }
}
